<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>async await</title>
</head>
<body>
    

    <script>
        
      {
        async function fn () {
            return 'async';
        }

        console.log(fn()); // 返回的是一个Promise对象 ：Promise {<resolved>: "async"}

      }

      {

        async function fn() {
            return Promise.resolve("hello async");
        }

        console.log(fn());// Promise {<pending>}

      }

      {
        async function fn() {
            return "hello async";
        }

        function gn() {
            return Promise.resolve('ok');
        }

        async function f () {
            let res = await fn();
            let s = await gn();
            console.log(res,s);
        }

        f();
      }


      {

          let p1 = new Promise((resolve,reject)=>{
            resolve('p1 success');
          });
          
          p1.then(d=>{
              console.log(d);
          });

      }

      {
        function func () {
            return new Promise((resolve,reject)=>{
                resolve('p2 success');
            });
        }
        async function f () {
            let res = await func();
            console.log(res);
        }

        console.log(f());
      }
        
       
    </script>
</body>
</html>